//=============================================================================
// rpg_scenes.js v1.6.2
//=============================================================================

//=============================================================================

/**
 * The Superclass of all scene within the game.
 * 
 * @class Scene_Base
 * @constructor 
 * @extends Stage
 */
 class Scene_Base extends Stage {
    constructor(){
        super();
        this.initialize.apply(this, arguments);
    }

    
    /**
     * Create a instance of Scene_Base.
     * 
     * @instance 
     * @memberof Scene_Base
     */
    initialize(): void{
        Stage.prototype.initialize.call(this);
        this._active = false;
        this._fadeSign = 0;
        this._fadeDuration = 0;
        this._fadeSprite = null;
        this._imageReservationId = Utils.generateRuntimeId();
    }
    _active: boolean;
    _fadeSign: number;
    _fadeDuration: number;
    _fadeSprite: ScreenSprite;
    _imageReservationId: number;
    _spriteset: Spriteset_Base;

    /**
     * Attach a reservation to the reserve queue.
     * 
     * @method attachReservation
     * @instance 
     * @memberof Scene_Base
     */
    attachReservation(): void{
        ImageManager.setDefaultReservationId(this._imageReservationId);
    }

    /**
     * Remove the reservation from the Reserve queue.
     * 
     * @method detachReservation
     * @instance 
     * @memberof Scene_Base
     */
    detachReservation(): void{
        ImageManager.releaseReservation(this._imageReservationId);
    }

    /**
     * Create the components and add them to the rendering process.
     * 
     * @method create
     * @instance 
     * @memberof Scene_Base
     */
    create(): void{}

    /**
     * Returns whether the scene is active or not.
     * 
     * @method isActive
     * @instance 
     * @memberof Scene_Base
     * @return {Boolean} return true if the scene is active
     */
    isActive(): boolean{ 
        return this._active;
     }

    /**
     * Return whether the scene is ready to start or not.
     * 
     * @method isReady
     * @instance 
     * @memberof Scene_Base
     * @return {Boolean} Return true if the scene is ready to start
     */
    isReady(): boolean{ 
        return ImageManager.isReady();
     }

    /**
     * Start the scene processing.
     * 
     * @method start
     * @instance 
     * @memberof Scene_Base
     */
    start(): void{
        this._active = true;
    }

    /**
     * Update the scene processing each new frame.
     * 
     * @method update
     * @instance 
     * @memberof Scene_Base
     */
    update(): void{
        this.updateFade();
        this.updateChildren();
    }

    /**
     * Stop the scene processing.
     * 
     * @method stop
     * @instance 
     * @memberof Scene_Base
     */
    stop(): void{
        this._active = false;
    }

    /**
     * Return whether the scene is busy or not.
     * 
     * @method isBusy
     * @instance
     * @memberof Scene_Base
     * @return {Boolean} Return true if the scene is currently busy
     */
    isBusy(): boolean{ 
        return this._fadeDuration > 0;
    }

    /**
     * Terminate the scene before switching to a another scene.
     * 
     * @method terminate
     * @instance 
     * @memberof Scene_Base
     */
    terminate(): void{}

    /**
     * Create the layer for the windows children
     * and add it to the rendering process.
     * 
     * @method createWindowLayer
     * @instance 
     * @memberof Scene_Base
     */
    createWindowLayer(): void{
        var width = Graphics.boxWidth;
        var height = Graphics.boxHeight;
        var x = (Graphics.width - width) / 2;
        var y = (Graphics.height - height) / 2;
        this._windowLayer = new WindowLayer();
        this._windowLayer.move(x, y, width, height);
        this.addChild(this._windowLayer);
    }
    

    /**
     * Add the children window to the windowLayer processing.
     * 
     * @method addWindow
     * @instance 
     * @memberof Scene_Base
     */
    addWindow(window: Window_Base): void{
        this._windowLayer.addChild(window);
    }

    /**
     * Request a fadeIn screen process.
     * 
     * @method startFadeIn
     * @param {Number} [duration=30] The time the process will take for fadeIn the screen
     * @param {Boolean} [white=false] If true the fadein will be process with a white color else it's will be black
     * 
     * @instance 
     * @memberof Scene_Base
     */
    startFadeIn(duration?: number, white?: boolean): void{
        this.createFadeSprite(white);
        this._fadeSign = 1;
        this._fadeDuration = duration || 30;
        this._fadeSprite.opacity = 255;
    }
    
    /**
     * Request a fadeOut screen process.
     * 
     * @method startFadeOut
     * @param {Number} [duration=30] The time the process will take for fadeOut the screen
     * @param {Boolean} [white=false] If true the fadeOut will be process with a white color else it's will be black
     * 
     * @instance 
     * @memberof Scene_Base
     */
    startFadeOut(duration?: number, white?: boolean): void{
        this.createFadeSprite(white);
        this._fadeSign = -1;
        this._fadeDuration = duration || 30;
        this._fadeSprite.opacity = 0;
    }
    
    /**
     * Create a Screen sprite for the fadein and fadeOut purpose and
     * add it to the rendering process.
     * 
     * @method createFadeSprite
     * @instance 
     * @memberof Scene_Base
     */
    createFadeSprite(white?: boolean): void{
        if (!this._fadeSprite) {
            this._fadeSprite = new ScreenSprite();
            this.addChild(this._fadeSprite);
        }
        if (white) {
            this._fadeSprite.setWhite();
        } else {
            this._fadeSprite.setBlack();
        }
    }
   
   /**
     * Update the screen fade processing.
     * 
     * @method updateFade
     * @instance 
     * @memberof Scene_Base
     */
    updateFade(): void{
        if (this._fadeDuration > 0) {
            var d = this._fadeDuration;
            if (this._fadeSign > 0) {
                this._fadeSprite.opacity -= this._fadeSprite.opacity / d;
            } else {
                this._fadeSprite.opacity += (255 - this._fadeSprite.opacity) / d;
            }
            this._fadeDuration--;
        }
    }

    /**
     * Update the children of the scene EACH frame.
     * 
     * @method updateChildren
     * @instance 
     * @memberof Scene_Base
     */
    updateChildren(): void{
        this.children.forEach(function(child) {
            if (child.update) {
                child.update();
            }
        });
    }

    /**
     * Pop the scene from the stack array and switch to the
     * previous scene.
     * 
     * @method popScene
     * @instance 
     * @memberof Scene_Base
     */
    popScene(): void{
        SceneManager.pop();
    }

    /**
     * Check whether the game should be triggering a gameover.
     * 
     * @method checkGameover
     * @instance 
     * @memberof Scene_Base
     */
    checkGameover(): void{
        if ($gameParty.isAllDead()) {
            SceneManager.goto(Scene_Gameover);
        }
    }

    /**
     * Slowly fade out all the visual and audio of the scene.
     * 
     * @method fadeOutAll
     * @instance 
     * @memberof Scene_Base
     */
    fadeOutAll(): void{
        var time = this.slowFadeSpeed() / 60;
        AudioManager.fadeOutBgm(time);
        AudioManager.fadeOutBgs(time);
        AudioManager.fadeOutMe(time);
        this.startFadeOut(this.slowFadeSpeed());
    }

    /**
     * Return the screen fade speed value.
     * 
     * @method fadeSpeed
     * @instance 
     * @memberof Scene_Base
     * @return {Number} Return the fade speed
     */
    fadeSpeed(): number{ 
        return 24;
    }

    /**
     * Return a slow screen fade speed value.
     * 
     * @method slowFadeSpeed
     * @instance 
     * @memberof Scene_Base
     * @return {Number} Return the fade speed
     */
    slowFadeSpeed(): number{ 
        return this.fadeSpeed() * 2;
    }

    _windowLayer: WindowLayer;
}

//-----------------------------------------------------------------------------
// Scene_Boot
//
// The scene class for initializing the entire game.

 class Scene_Boot extends Scene_Base {
    constructor(){
        super();
        this.initialize.apply(this, arguments);
    }
    initialize(): void{
        Scene_Base.prototype.initialize.call(this);
        this._startDate = Date.now();
    }
    _startDate: number;
    create(): void{
        Scene_Base.prototype.create.call(this);
        DataManager.loadDatabase();
        ConfigManager.load();
        this.loadSystemWindowImage();
    }
    static loadSystemImages(): void{
        ImageManager.reserveSystem('Window');
    }
    loadSystemWindowImage(): void{
        ImageManager.reserveSystem('IconSet');
        ImageManager.reserveSystem('Balloon');
        ImageManager.reserveSystem('Shadow1');
        ImageManager.reserveSystem('Shadow2');
        ImageManager.reserveSystem('Damage');
        ImageManager.reserveSystem('States');
        ImageManager.reserveSystem('Weapons1');
        ImageManager.reserveSystem('Weapons2');
        ImageManager.reserveSystem('Weapons3');
        ImageManager.reserveSystem('ButtonSet');
    }
    isReady(): boolean{
        if (Scene_Base.prototype.isReady.call(this)) {
            return DataManager.isDatabaseLoaded() && this.isGameFontLoaded();
        } else {
            return false;
        }
    }
    isGameFontLoaded(): boolean{
        if (Graphics.isFontLoaded('GameFont')) {
            return true;
        } else if (!Graphics.canUseCssFontLoading()){
            var elapsed = Date.now() - this._startDate;
            if (elapsed >= 60000) {
                throw new Error('Failed to load GameFont');
            }
        }
    }
    start(): void{
        Scene_Base.prototype.start.call(this);
        SoundManager.preloadImportantSounds();
        if (DataManager.isBattleTest()) {
            DataManager.setupBattleTest();
            SceneManager.goto(Scene_Battle);
        } else if (DataManager.isEventTest()) {
            DataManager.setupEventTest();
            SceneManager.goto(Scene_Map);
        } else {
            this.checkPlayerLocation();
            DataManager.setupNewGame();
            SceneManager.goto(Scene_Title);
            Window_TitleCommand.initCommandPosition();
        }
        this.updateDocumentTitle();
    }
    updateDocumentTitle(): void{
        document.title = $dataSystem.gameTitle;
    }
    checkPlayerLocation(): void{
        if ($dataSystem.startMapId === 0) {
            throw new Error('Player\'s starting position is not set');
        }
    }
}

//-----------------------------------------------------------------------------
// Scene_Title
//
// The scene class of the title screen.

 class Scene_Title extends Scene_Base {
    constructor(){
        super();
    }
    initialize(): void{
        Scene_Base.prototype.initialize.call(this);
    }

    create(): void{
        Scene_Base.prototype.create.call(this);
        this.createBackground();
        this.createForeground();
        this.createWindowLayer();
        this.createCommandWindow();
    }
    start(): void{
        Scene_Base.prototype.start.call(this);
        SceneManager.clearStack();
        this.centerSprite(this._backSprite1);
        this.centerSprite(this._backSprite2);
        this.playTitleMusic();
        this.startFadeIn(this.fadeSpeed(), false);
    }
    update(): void{
        if (!this.isBusy()) {
            this._commandWindow.open();
        }
        Scene_Base.prototype.update.call(this);
    }
    _commandWindow: Window_TitleCommand;
    isBusy(): boolean{
        return this._commandWindow.isClosing() || Scene_Base.prototype.isBusy.call(this);
    }
    terminate(): void{
        Scene_Base.prototype.terminate.call(this);
        SceneManager.snapForBackground();
    }
    createBackground(): void{
        this._backSprite1 = new Sprite(ImageManager.loadTitle1($dataSystem.title1Name));
        this._backSprite2 = new Sprite(ImageManager.loadTitle2($dataSystem.title2Name));
        this.addChild(this._backSprite1);
        this.addChild(this._backSprite2);
    }
    _backSprite1: Sprite|any;
    _backSprite2: Sprite|any;
    createForeground(): void{
        this._gameTitleSprite = new Sprite(new Bitmap(Graphics.width, Graphics.height));
        this.addChild(this._gameTitleSprite);
        if ($dataSystem.optDrawTitle) {
            this.drawGameTitle();
        }
    }
    _gameTitleSprite: Sprite;
    drawGameTitle(): void{
        var x = 20;
        var y = Graphics.height / 4;
        var maxWidth = Graphics.width - x * 2;
        var text = $dataSystem.gameTitle;
        this._gameTitleSprite.bitmap.outlineColor = 'black';
        this._gameTitleSprite.bitmap.outlineWidth = 8;
        this._gameTitleSprite.bitmap.fontSize = 72;
        this._gameTitleSprite.bitmap.drawText(text, x, y, maxWidth, 48, 'center');
    }
    centerSprite(sprite: Sprite_Base): void{
        sprite.x = Graphics.width / 2;
        sprite.y = Graphics.height / 2;
        sprite.anchor.x = 0.5;
        sprite.anchor.y = 0.5;
    }
    createCommandWindow(): void{
        this._commandWindow = new Window_TitleCommand();
        this._commandWindow.setHandler('newGame',  this.commandNewGame.bind(this));
        this._commandWindow.setHandler('continue', this.commandContinue.bind(this));
        this._commandWindow.setHandler('options',  this.commandOptions.bind(this));
        this.addWindow(this._commandWindow);
    }
    commandNewGame(): void{
        DataManager.setupNewGame();
        this._commandWindow.close();
        this.fadeOutAll();
        SceneManager.goto(Scene_Map);
    }
    commandContinue(): void{
        this._commandWindow.close();
        SceneManager.push(Scene_Load);
    }
    commandOptions(): void{
        this._commandWindow.close();
        SceneManager.push(Scene_Options);
    }
    playTitleMusic(): void{
        AudioManager.playBgm($dataSystem.titleBgm);
        AudioManager.stopBgs();
        AudioManager.stopMe();
    }
}

//-----------------------------------------------------------------------------
// Scene_Map
//
// The scene class of the map screen.

 class Scene_Map extends Scene_Base {
    constructor(){
        super();
        this.initialize.apply(this, arguments);
    }
    initialize(): void{
        Scene_Base.prototype.initialize.call(this);
        this._waitCount = 0;
        this._encounterEffectDuration = 0;
        this._mapLoaded = false;
        this._touchCount = 0;
    }
    _waitCount: number;
    _encounterEffectDuration: number;
    _mapLoaded: boolean;
    _touchCount: number;

    create(): void{
        Scene_Base.prototype.create.call(this);
        this._transfer = $gamePlayer.isTransferring();
        var mapId = this._transfer ? $gamePlayer.newMapId() : $gameMap.mapId();
        DataManager.loadMapData(mapId);
    }
    _transfer: boolean;

    isReady(): boolean{
        if (!this._mapLoaded && DataManager.isMapLoaded()) {
            this.onMapLoaded();
            this._mapLoaded = true;
        }
        return this._mapLoaded && Scene_Base.prototype.isReady.call(this);
    }
    onMapLoaded(): void{
        if (this._transfer) {
            $gamePlayer.performTransfer();
        }
        this.createDisplayObjects();
    }
    start(): void{
        Scene_Base.prototype.start.call(this);
        SceneManager.clearStack();
        if (this._transfer) {
            this.fadeInForTransfer();
            this._mapNameWindow.open();
            $gameMap.autoplay();
        } else if (this.needsFadeIn()) {
            this.startFadeIn(this.fadeSpeed(), false);
        }
        this.menuCalling = false;
    }
    menuCalling: boolean;
    update(): void{
        this.updateDestination();
        this.updateMainMultiply();
        if (this.isSceneChangeOk()) {
            this.updateScene();
        } else if (SceneManager.isNextScene(Scene_Battle)) {
            this.updateEncounterEffect();
        }
        this.updateWaitCount();
        Scene_Base.prototype.update.call(this);
    }
    updateMainMultiply(): void{
        this.updateMain();
        if (this.isFastForward()) {
            this.updateMain();
        }
    }
    updateMain(): void{
        var active = this.isActive();
        $gameMap.update(active);
        $gamePlayer.update(active);
        $gameTimer.update(active);
        $gameScreen.update();
    }
    isFastForward(): boolean{
        return ($gameMap.isEventRunning() && !SceneManager.isSceneChanging() &&
        (Input.isLongPressed('ok') || TouchInput.isLongPressed()));
    }
    stop(): void{
        Scene_Base.prototype.stop.call(this);
        $gamePlayer.straighten();
        this._mapNameWindow.close();
        if (this.needsSlowFadeOut()) {
            this.startFadeOut(this.slowFadeSpeed(), false);
        } else if (SceneManager.isNextScene(Scene_Map)) {
            this.fadeOutForTransfer();
        } else if (SceneManager.isNextScene(Scene_Battle)) {
            this.launchBattle();
        }
    }
    isBusy(): boolean{
        return ((this._messageWindow && this._messageWindow.isClosing()) ||
        this._waitCount > 0 || this._encounterEffectDuration > 0 ||
        Scene_Base.prototype.isBusy.call(this));
    }
    terminate(): void{
        Scene_Base.prototype.terminate.call(this);
        if (!SceneManager.isNextScene(Scene_Battle)) {
            this._spriteset.update();
            this._mapNameWindow.hide();
            SceneManager.snapForBackground();
        } else {
            ImageManager.clearRequest();
        }
    
        if (SceneManager.isNextScene(Scene_Map)) {
            ImageManager.clearRequest();
        }
    
        $gameScreen.clearZoom();
    
        this.removeChild(this._fadeSprite);
        this.removeChild(this._mapNameWindow);
        this.removeChild(this._windowLayer);
        this.removeChild(this._spriteset);
    }
    needsFadeIn(): boolean{
        return (SceneManager.isPreviousScene(Scene_Battle) ||
        SceneManager.isPreviousScene(Scene_Load));
    }
    needsSlowFadeOut(): boolean{
        return (SceneManager.isNextScene(Scene_Title) ||
        SceneManager.isNextScene(Scene_Gameover));
    }
    updateWaitCount(): boolean{
        if (this._waitCount > 0) {
            this._waitCount--;
            return true;
        }
        return false;
    }
    updateDestination(): void{
        if (this.isMapTouchOk()) {
            this.processMapTouch();
        } else {
            $gameTemp.clearDestination();
            this._touchCount = 0;
        }
    }
    isMapTouchOk(): boolean{
        return this.isActive() && $gamePlayer.canMove();
    }
    processMapTouch(): void{
        if (TouchInput.isTriggered() || this._touchCount > 0) {
            if (TouchInput.isPressed()) {
                if (this._touchCount === 0 || this._touchCount >= 15) {
                    var x = $gameMap.canvasToMapX(TouchInput.x);
                    var y = $gameMap.canvasToMapY(TouchInput.y);
                    $gameTemp.setDestination(x, y);
                }
                this._touchCount++;
            } else {
                this._touchCount = 0;
            }
        }
    }
    isSceneChangeOk(): boolean{
        return this.isActive() && !$gameMessage.isBusy();
    }
    updateScene(): void{
        this.checkGameover();
        if (!SceneManager.isSceneChanging()) {
            this.updateTransferPlayer();
        }
        if (!SceneManager.isSceneChanging()) {
            this.updateEncounter();
        }
        if (!SceneManager.isSceneChanging()) {
            this.updateCallMenu();
        }
        if (!SceneManager.isSceneChanging()) {
            this.updateCallDebug();
        }
    }
    createDisplayObjects(): void{
        this.createSpriteset();
        this.createMapNameWindow();
        this.createWindowLayer();
        this.createAllWindows();
    }
    createSpriteset(): void{
        this._spriteset = new Spriteset_Map();
        this.addChild(this._spriteset);
    }
    _spriteset: Spriteset_Map;
    createAllWindows(): void{
        this.createMessageWindow();
        this.createScrollTextWindow();
    }
    createMapNameWindow(): void{
        this._mapNameWindow = new Window_MapName();
        this.addChild(this._mapNameWindow);
    }
    _mapNameWindow: Window_MapName;
    createMessageWindow(): void{
        this._messageWindow = new Window_Message();
        this.addWindow(this._messageWindow);
        this._messageWindow.subWindows().forEach((window: Window_Base) => {
            this.addWindow(window);
        });
    }
    _messageWindow: Window_Message;
    createScrollTextWindow(): void{
        this._scrollTextWindow = new Window_ScrollText();
        this.addWindow(this._scrollTextWindow);
    }
    _scrollTextWindow: Window_ScrollText;
    updateTransferPlayer(): void{
        if ($gamePlayer.isTransferring()) {
            SceneManager.goto(Scene_Map);
        }
    }
    updateEncounter(): void{
        if ($gamePlayer.executeEncounter()) {
            SceneManager.push(Scene_Battle);
        }
    }
    updateCallMenu(): void{
        if (this.isMenuEnabled()) {
            if (this.isMenuCalled()) {
                this.menuCalling = true;
            }
            if (this.menuCalling && !$gamePlayer.isMoving()) {
                this.callMenu();
            }
        } else {
            this.menuCalling = false;
        }
    }
    isMenuEnabled(): boolean{
        return $gameSystem.isMenuEnabled() && !$gameMap.isEventRunning();
    }
    isMenuCalled(): boolean{
        return Input.isTriggered('menu') || TouchInput.isCancelled();

    }
    callMenu(): void{
        SoundManager.playOk();
        SceneManager.push(Scene_Menu);
        Window_MenuCommand.initCommandPosition();
        $gameTemp.clearDestination();
        this._mapNameWindow.hide();
        this._waitCount = 2;
    }
    updateCallDebug(): void{
        if (this.isDebugCalled()) {
            SceneManager.push(Scene_Debug);
        }
    }
    isDebugCalled(): boolean{
        return Input.isTriggered('debug') && $gameTemp.isPlaytest();

    }
    fadeInForTransfer(): void{
        var fadeType = $gamePlayer.fadeType();
        switch (fadeType) {
        case 0: case 1:
            this.startFadeIn(this.fadeSpeed(), fadeType === 1);
            break;
        }
    }
    fadeOutForTransfer(): void{
        var fadeType = $gamePlayer.fadeType();
        switch (fadeType) {
        case 0: case 1:
            this.startFadeOut(this.fadeSpeed(), fadeType === 1);
            break;
        }
    }
    launchBattle(): void{
        BattleManager.saveBgmAndBgs();
        this.stopAudioOnBattleStart();
        SoundManager.playBattleStart();
        this.startEncounterEffect();
        this._mapNameWindow.hide();
    }
    stopAudioOnBattleStart(): void{
        if (!AudioManager.isCurrentBgm($gameSystem.battleBgm())) {
            AudioManager.stopBgm();
        }
        AudioManager.stopBgs();
        AudioManager.stopMe();
        AudioManager.stopSe();
    }
    startEncounterEffect(): void{
        this._spriteset.hideCharacters();
        this._encounterEffectDuration = this.encounterEffectSpeed();
    }
    updateEncounterEffect(): void{
        if (this._encounterEffectDuration > 0) {
            this._encounterEffectDuration--;
            var speed = this.encounterEffectSpeed();
            var n = speed - this._encounterEffectDuration;
            var p = n / speed;
            var q = ((p - 1) * 20 * p + 5) * p + 1;
            var zoomX = $gamePlayer.screenX();
            var zoomY = $gamePlayer.screenY() - 24;
            if (n === 2) {
                $gameScreen.setZoom(zoomX, zoomY, 1);
                this.snapForBattleBackground();
                this.startFlashForEncounter(speed / 2);
            }
            $gameScreen.setZoom(zoomX, zoomY, q);
            if (n === Math.floor(speed / 6)) {
                this.startFlashForEncounter(speed / 2);
            }
            if (n === Math.floor(speed / 2)) {
                BattleManager.playBattleBgm();
                this.startFadeOut(this.fadeSpeed());
            }
        }
    }
    snapForBattleBackground(): void{
        this._windowLayer.visible = false;
        SceneManager.snapForBackground();
        this._windowLayer.visible = true;
    }
    startFlashForEncounter(duration: number): void{
        var color = [255, 255, 255, 255];
        $gameScreen.startFlash(color, duration);
    }
    encounterEffectSpeed(): number{
        return 60;

    }
}

//-----------------------------------------------------------------------------
// Scene_MenuBase
//
// The superclass of all the menu-type scenes.

 class Scene_MenuBase extends Scene_Base {
    constructor(){
        super();
        this.initialize.apply(this, arguments);
    }
    initialize(): void {
        Scene_Base.prototype.initialize.call(this);
    };

    create(): void {
        Scene_Base.prototype.create.call(this);
        this.createBackground();
        this.updateActor();
        this.createWindowLayer();
    };
    actor(): Game_Actor {
        return this._actor;
    };
    _actor: Game_Actor;
    updateActor(): void {
        this._actor = $gameParty.menuActor();
    };
    createBackground(): void {
        this._backgroundSprite = new Sprite();
        this._backgroundSprite.bitmap = SceneManager.backgroundBitmap();
        this.addChild(this._backgroundSprite);
    };
    _backgroundSprite: Sprite;
    setBackgroundOpacity(opacity: number): void {
        this._backgroundSprite.opacity = opacity;
    };
    createHelpWindow(): void {
        this._helpWindow = new Window_Help();
        this.addWindow(this._helpWindow);
    };
    _helpWindow: Window_Help;
    nextActor(): void {
        $gameParty.makeMenuActorNext();
        this.updateActor();
        this.onActorChange();
    };
    previousActor(): void {
        $gameParty.makeMenuActorPrevious();
        this.updateActor();
        this.onActorChange();
    };
    onActorChange(): void {
    };
}

//-----------------------------------------------------------------------------
// Scene_Menu
//
// The scene class of the menu screen.

 class Scene_Menu extends Scene_MenuBase {
    constructor() {
        super();
        this.initialize.apply(this, arguments);
    }
    initialize(): void {
        Scene_MenuBase.prototype.initialize.call(this);
    };

    create(): void {
        Scene_MenuBase.prototype.create.call(this);
        this.createCommandWindow();
        this.createGoldWindow();
        this.createStatusWindow();
    };
    start(): void {
        Scene_MenuBase.prototype.start.call(this);
        this._statusWindow.refresh();
    };
    _statusWindow: Window_MenuStatus;
    createCommandWindow(): void {
        this._commandWindow = new Window_MenuCommand(0, 0);
        this._commandWindow.setHandler('item',      this.commandItem.bind(this));
        this._commandWindow.setHandler('skill',     this.commandPersonal.bind(this));
        this._commandWindow.setHandler('equip',     this.commandPersonal.bind(this));
        this._commandWindow.setHandler('status',    this.commandPersonal.bind(this));
        this._commandWindow.setHandler('formation', this.commandFormation.bind(this));
        this._commandWindow.setHandler('options',   this.commandOptions.bind(this));
        this._commandWindow.setHandler('save',      this.commandSave.bind(this));
        this._commandWindow.setHandler('gameEnd',   this.commandGameEnd.bind(this));
        this._commandWindow.setHandler('cancel',    this.popScene.bind(this));
        this.addWindow(this._commandWindow);
    };
    _commandWindow: Window_MenuCommand;
    createGoldWindow(): void {
        this._goldWindow = new Window_Gold(0, 0);
        this._goldWindow.y = Graphics.boxHeight - this._goldWindow.height;
        this.addWindow(this._goldWindow);
    };
    _goldWindow: Window_Gold;
    createStatusWindow(): void {
        this._statusWindow = new Window_MenuStatus(this._commandWindow.width, 0);
        this._statusWindow.reserveFaceImages();
        this.addWindow(this._statusWindow);
    };
    commandItem(): void {
        SceneManager.push(Scene_Item);
    };
    commandPersonal(): void {
        this._statusWindow.setFormationMode(false);
        this._statusWindow.selectLast();
        this._statusWindow.activate();
        this._statusWindow.setHandler('ok',     this.onPersonalOk.bind(this));
        this._statusWindow.setHandler('cancel', this.onPersonalCancel.bind(this));
    };
    commandFormation(): void {
        this._statusWindow.setFormationMode(true);
        this._statusWindow.selectLast();
        this._statusWindow.activate();
        this._statusWindow.setHandler('ok',     this.onFormationOk.bind(this));
        this._statusWindow.setHandler('cancel', this.onFormationCancel.bind(this));
    };
    commandOptions(): void {
        SceneManager.push(Scene_Options);
    };
    commandSave(): void {
        SceneManager.push(Scene_Save);
    };
    commandGameEnd(): void {
        SceneManager.push(Scene_GameEnd);
    };
    onPersonalOk(): void {
        switch (this._commandWindow.currentSymbol()) {
        case 'skill':
            SceneManager.push(Scene_Skill);
            break;
        case 'equip':
            SceneManager.push(Scene_Equip);
            break;
        case 'status':
            SceneManager.push(Scene_Status);
            break;
        }
    };
    onPersonalCancel(): void {
        this._statusWindow.deselect();
        this._commandWindow.activate();
    };
    onFormationOk(): void {
        var index = this._statusWindow.index();
        var actor = $gameParty.members()[index];
        var pendingIndex = this._statusWindow.pendingIndex();
        if (pendingIndex >= 0) {
            $gameParty.swapOrder(index, pendingIndex);
            this._statusWindow.setPendingIndex(-1);
            this._statusWindow.redrawItem(index);
        } else {
            this._statusWindow.setPendingIndex(index);
        }
        this._statusWindow.activate();
    };
    onFormationCancel(): void {
        if (this._statusWindow.pendingIndex() >= 0) {
            this._statusWindow.setPendingIndex(-1);
            this._statusWindow.activate();
        } else {
            this._statusWindow.deselect();
            this._commandWindow.activate();
        }
    };
}

//-----------------------------------------------------------------------------
// Scene_ItemBase
//
// The superclass of Scene_Item and Scene_Skill.

 class Scene_ItemBase extends Scene_MenuBase {
    constructor() {
        super();
        this.initialize.apply(this, arguments);
    }
    initialize(): void {
        Scene_MenuBase.prototype.initialize.call(this);
    };

    create(): void{
        Scene_MenuBase.prototype.create.call(this);
    };
    createActorWindow(): void{
        this._actorWindow = new Window_MenuActor();
        this._actorWindow.setHandler('ok',     this.onActorOk.bind(this));
        this._actorWindow.setHandler('cancel', this.onActorCancel.bind(this));
        this.addWindow(this._actorWindow);
    };
    _actorWindow: Window_MenuActor;
    item(): RPGMakerMV.DataAnyItem | RPGMakerMV.DataSkill{
        return this._itemWindow.item();
    };
    user(): Game_Actor{
        return null;
    };
    isCursorLeft(): boolean{
        return this._itemWindow.index() % 2 === 0;
    };
    showSubWindow(window: Window_Base): void {
        window.x = this.isCursorLeft() ? Graphics.boxWidth - window.width : 0;
        window.show();
        window.activate();
    };
    hideSubWindow(window: Window_Base): void {
        window.hide();
        window.deactivate();
        this.activateItemWindow();
    };
    onActorOk(): void {
        if (this.canUse()) {
            this.useItem();
        } else {
            SoundManager.playBuzzer();
        }
    };
    onActorCancel(): void{
        this.hideSubWindow(this._actorWindow);
    };
    determineItem(): void {
        var action = new Game_Action(this.user());
        var item = this.item();
        action.setItemObject(item);
        if (action.isForFriend()) {
            this.showSubWindow(this._actorWindow);
            this._actorWindow.selectForItem(this.item());
        } else {
            this.useItem();
            this.activateItemWindow();
        }
    };
    //FIXME 后加的方法
    playSeForItem(): void{
        throw new Error("Method not implemented.");
    }
    useItem(): void {
        this.playSeForItem();
        this.user().useItem(this.item());
        this.applyItem();
        this.checkCommonEvent();
        this.checkGameover();
        this._actorWindow.refresh();
    };
    activateItemWindow(): void {
        this._itemWindow.refresh();
        this._itemWindow.activate();
    };
    itemTargetActors(): void|any {
        var action = new Game_Action(this.user());
        action.setItemObject(this.item());
        if (!action.isForFriend()) {
            return [];
        } else if (action.isForAll()) {
            return $gameParty.members();
        } else {
            return [$gameParty.members()[this._actorWindow.index()]];
        }
    };
    canUse(): boolean{
        return this.user().canUse(this.item()) && this.isItemEffectsValid();
    };
    isItemEffectsValid(): boolean{
        var action = new Game_Action(this.user());
        action.setItemObject(this.item());
        return this.itemTargetActors().some((target: Game_Battler) => {
            return action.testApply(target);
        }, this);
    };
    applyItem(): void{
        var action = new Game_Action(this.user());
        action.setItemObject(this.item());
        this.itemTargetActors().forEach((target: Game_Battler) => {
            for (var i = 0; i < action.numRepeats(); i++) {
                action.apply(target);
            }
        }, this);
        action.applyGlobal();
    };
    checkCommonEvent(): void{
        if ($gameTemp.isCommonEventReserved()) {
            SceneManager.goto(Scene_Map);
        }
    };

    _itemWindow: Window_Selectable|any;
}

//-----------------------------------------------------------------------------
// Scene_Item
//
// The scene class of the item screen.

 class Scene_Item extends Scene_ItemBase {
    constructor(){
        super();
        this.initialize.apply(this, arguments);
    }
    initialize(): void {
        Scene_ItemBase.prototype.initialize.call(this);
    };
    create(): void{
        Scene_ItemBase.prototype.create.call(this);
        this.createHelpWindow();
        this.createCategoryWindow();
        this.createItemWindow();
        this.createActorWindow();
    };
    createCategoryWindow(): void{
        this._categoryWindow = new Window_ItemCategory();
        this._categoryWindow.setHelpWindow(this._helpWindow);
        this._categoryWindow.y = this._helpWindow.height;
        this._categoryWindow.setHandler('ok',     this.onCategoryOk.bind(this));
        this._categoryWindow.setHandler('cancel', this.popScene.bind(this));
        this.addWindow(this._categoryWindow);
    };
    _categoryWindow: Window_ItemCategory;
    createItemWindow(): void{
        var wy = this._categoryWindow.y + this._categoryWindow.height;
        var wh = Graphics.boxHeight - wy;
        this._itemWindow = new Window_ItemList(0, wy, Graphics.boxWidth, wh);
        this._itemWindow.setHelpWindow(this._helpWindow);
        this._itemWindow.setHandler('ok',     this.onItemOk.bind(this));
        this._itemWindow.setHandler('cancel', this.onItemCancel.bind(this));
        this.addWindow(this._itemWindow);
        this._categoryWindow.setItemWindow(this._itemWindow);
    };
    _itemWindow: Window_ItemList;
    user(): Game_Actor|any{
        var members = $gameParty.movableMembers();
        var bestActor = members[0];
        var bestPha = 0;
        for (var i = 0; i < members.length; i++) {
            if (members[i].pha > bestPha) {
                bestPha = members[i].pha;
                bestActor = members[i];
            }
        }
        return bestActor;
    };
    onCategoryOk(): void{
        this._itemWindow.activate();
        this._itemWindow.selectLast();
    };
    onItemOk(): void {
        $gameParty.setLastItem(this.item());
        this.determineItem();
    };
    onItemCancel(): void{
        this._itemWindow.deselect();
        this._categoryWindow.activate();
    };
    playSeForItem(): void{
        SoundManager.playUseItem();
    };
    useItem(): void{
        Scene_ItemBase.prototype.useItem.call(this);
        this._itemWindow.redrawCurrentItem();
    };
}

//-----------------------------------------------------------------------------
// Scene_Skill
//
// The scene class of the skill screen.

 class Scene_Skill extends Scene_ItemBase {
    constructor(){
        super();
        this.initialize.apply(this, arguments);
    }
    initialize(): void{
        Scene_ItemBase.prototype.initialize.call(this);
    };
    create(): void{
        Scene_ItemBase.prototype.create.call(this);
        this.createHelpWindow();
        this.createSkillTypeWindow();
        this.createStatusWindow();
        this.createItemWindow();
        this.createActorWindow();
    };
    start(): void{
        Scene_ItemBase.prototype.start.call(this);
        this.refreshActor();
    };
    createSkillTypeWindow(): void{
        var wy = this._helpWindow.height;
        this._skillTypeWindow = new Window_SkillType(0, wy);
        this._skillTypeWindow.setHelpWindow(this._helpWindow);
        this._skillTypeWindow.setHandler('skill',    this.commandSkill.bind(this));
        this._skillTypeWindow.setHandler('cancel',   this.popScene.bind(this));
        this._skillTypeWindow.setHandler('pagedown', this.nextActor.bind(this));
        this._skillTypeWindow.setHandler('pageup',   this.previousActor.bind(this));
        this.addWindow(this._skillTypeWindow);
    };
    _skillTypeWindow: Window_SkillType;
    createStatusWindow(): void{
        var wx = this._skillTypeWindow.width;
        var wy = this._helpWindow.height;
        var ww = Graphics.boxWidth - wx;
        var wh = this._skillTypeWindow.height;
        this._statusWindow = new Window_SkillStatus(wx, wy, ww, wh);
        this._statusWindow.reserveFaceImages();
        this.addWindow(this._statusWindow);
    };
    _statusWindow: Window_SkillStatus;
    createItemWindow(): void{
        var wx = 0;
        var wy = this._statusWindow.y + this._statusWindow.height;
        var ww = Graphics.boxWidth;
        var wh = Graphics.boxHeight - wy;
        this._itemWindow = new Window_SkillList(wx, wy, ww, wh);
        this._itemWindow.setHelpWindow(this._helpWindow);
        this._itemWindow.setHandler('ok',     this.onItemOk.bind(this));
        this._itemWindow.setHandler('cancel', this.onItemCancel.bind(this));
        this._skillTypeWindow.setSkillWindow(this._itemWindow);
        this.addWindow(this._itemWindow);
    };
    _itemWindow: Window_SkillList;
    refreshActor(): void{
        var actor = this.actor();
        this._skillTypeWindow.setActor(actor);
        this._statusWindow.setActor(actor);
        this._itemWindow.setActor(actor);
    };
    user(): Game_Actor{
        return this.actor();
    };
    commandSkill(): void{
        this._itemWindow.activate();
        this._itemWindow.selectLast();
    };
    onItemOk(): void{
        this.actor().setLastMenuSkill(this.item());
        this.determineItem();
    };
    onItemCancel(): void{
        this._itemWindow.deselect();
        this._skillTypeWindow.activate();
    };
    playSeForItem(): void{
        SoundManager.playUseSkill();
    };
    useItem(): void{
        Scene_ItemBase.prototype.useItem.call(this);
        this._statusWindow.refresh();
        this._itemWindow.refresh();
    };
    onActorChange(): void{
        this.refreshActor();
        this._skillTypeWindow.activate();
    };
}

//-----------------------------------------------------------------------------
// Scene_Equip
//
// The scene class of the equipment screen.

 class Scene_Equip extends Scene_MenuBase {
    constructor(){
        super();
        this.initialize.apply(this, arguments);
    }
    initialize(): void {
        Scene_MenuBase.prototype.initialize.call(this);
    };
    create(): void {
        Scene_MenuBase.prototype.create.call(this);
        this.createHelpWindow();
        this.createStatusWindow();
        this.createCommandWindow();
        this.createSlotWindow();
        this.createItemWindow();
        this.refreshActor();
    };
    createStatusWindow(): void {
        this._statusWindow = new Window_EquipStatus(0, this._helpWindow.height);
        this.addWindow(this._statusWindow);
    };
    _statusWindow: Window_EquipStatus;
    createCommandWindow(): void {
        var wx = this._statusWindow.width;
        var wy = this._helpWindow.height;
        var ww = Graphics.boxWidth - this._statusWindow.width;
        this._commandWindow = new Window_EquipCommand(wx, wy, ww);
        this._commandWindow.setHelpWindow(this._helpWindow);
        this._commandWindow.setHandler('equip',    this.commandEquip.bind(this));
        this._commandWindow.setHandler('optimize', this.commandOptimize.bind(this));
        this._commandWindow.setHandler('clear',    this.commandClear.bind(this));
        this._commandWindow.setHandler('cancel',   this.popScene.bind(this));
        this._commandWindow.setHandler('pagedown', this.nextActor.bind(this));
        this._commandWindow.setHandler('pageup',   this.previousActor.bind(this));
        this.addWindow(this._commandWindow);
    };
    _commandWindow: Window_EquipCommand;
    createSlotWindow(): void {
        var wx = this._statusWindow.width;
        var wy = this._commandWindow.y + this._commandWindow.height;
        var ww = Graphics.boxWidth - this._statusWindow.width;
        var wh = this._statusWindow.height - this._commandWindow.height;
        this._slotWindow = new Window_EquipSlot(wx, wy, ww, wh);
        this._slotWindow.setHelpWindow(this._helpWindow);
        this._slotWindow.setStatusWindow(this._statusWindow);
        this._slotWindow.setHandler('ok',       this.onSlotOk.bind(this));
        this._slotWindow.setHandler('cancel',   this.onSlotCancel.bind(this));
        this.addWindow(this._slotWindow);
    };
    _slotWindow: Window_EquipSlot;
    createItemWindow(): void {
        var wx = 0;
        var wy = this._statusWindow.y + this._statusWindow.height;
        var ww = Graphics.boxWidth;
        var wh = Graphics.boxHeight - wy;
        this._itemWindow = new Window_EquipItem(wx, wy, ww, wh);
        this._itemWindow.setHelpWindow(this._helpWindow);
        this._itemWindow.setStatusWindow(this._statusWindow);
        this._itemWindow.setHandler('ok',     this.onItemOk.bind(this));
        this._itemWindow.setHandler('cancel', this.onItemCancel.bind(this));
        this._slotWindow.setItemWindow(this._itemWindow);
        this.addWindow(this._itemWindow);
    };
    _itemWindow: Window_EquipItem;
    refreshActor(): void {
        var actor = this.actor();
        this._statusWindow.setActor(actor);
        this._slotWindow.setActor(actor);
        this._itemWindow.setActor(actor);
    };
    commandEquip(): void {
        this._slotWindow.activate();
        this._slotWindow.select(0);
    };
    commandOptimize(): void {
        SoundManager.playEquip();
        this.actor().optimizeEquipments();
        this._statusWindow.refresh();
        this._slotWindow.refresh();
        this._commandWindow.activate();
    };
    commandClear(): void {
        SoundManager.playEquip();
        this.actor().clearEquipments();
        this._statusWindow.refresh();
        this._slotWindow.refresh();
        this._commandWindow.activate();
    };
    onSlotOk(): void {
        this._itemWindow.activate();
        this._itemWindow.select(0);
    };
    onSlotCancel(): void {
        this._slotWindow.deselect();
        this._commandWindow.activate();
    };
    onItemOk(): void {
        SoundManager.playEquip();
        this.actor().changeEquip(this._slotWindow.index(), this._itemWindow.item());
        this._slotWindow.activate();
        this._slotWindow.refresh();
        this._itemWindow.deselect();
        this._itemWindow.refresh();
        this._statusWindow.refresh();
    };
    onItemCancel(): void {
        this._slotWindow.activate();
        this._itemWindow.deselect();
    };
    onActorChange(): void {
        this.refreshActor();
        this._commandWindow.activate();
    };
}

//-----------------------------------------------------------------------------
// Scene_Status
//
// The scene class of the status screen.

 class Scene_Status extends Scene_MenuBase {
    constructor(){
        super();
        this.initialize.apply(this, arguments);
    }
    initialize(): void {
        Scene_MenuBase.prototype.initialize.call(this);
    };
    create(): void {
        Scene_MenuBase.prototype.create.call(this);
        this._statusWindow = new Window_Status();
        this._statusWindow.setHandler('cancel',   this.popScene.bind(this));
        this._statusWindow.setHandler('pagedown', this.nextActor.bind(this));
        this._statusWindow.setHandler('pageup',   this.previousActor.bind(this));
        this._statusWindow.reserveFaceImages();
        this.addWindow(this._statusWindow);
    };
    start(): void {
        Scene_MenuBase.prototype.start.call(this);
        this.refreshActor();
    };
    _statusWindow: Window_Status;
    refreshActor(): void{
        var actor = this.actor();
        this._statusWindow.setActor(actor);
    };
    onActorChange(): void{
        this.refreshActor();
        this._statusWindow.activate();
    };
}

//-----------------------------------------------------------------------------
// Scene_Options
//
// The scene class of the options screen.

 class Scene_Options extends Scene_MenuBase {
    constructor(){
        super();
        this.initialize.apply(this, arguments);
    }
    initialize(): void {
        Scene_MenuBase.prototype.initialize.call(this);
    };
    create(): void{
        Scene_MenuBase.prototype.create.call(this);
        this.createOptionsWindow();
    };
    terminate(): void{
        Scene_MenuBase.prototype.terminate.call(this);
        ConfigManager.save();
    };
    createOptionsWindow(): void{
        this._optionsWindow = new Window_Options();
        this._optionsWindow.setHandler('cancel', this.popScene.bind(this));
        this.addWindow(this._optionsWindow);
    };
    _optionsWindow: Window_Options;
}

//-----------------------------------------------------------------------------
// Scene_File
//
// The superclass of Scene_Save and Scene_Load.

 class Scene_File extends Scene_MenuBase {
    constructor(){
        super();
        this.initialize.apply(this, arguments);
    }
    initialize(): void{
        Scene_MenuBase.prototype.initialize.call(this);
    };
    create(): void{
        Scene_MenuBase.prototype.create.call(this);
        DataManager.loadAllSavefileImages();
        this.createHelpWindow();
        this.createListWindow();
    };
    start(): void {
        Scene_MenuBase.prototype.start.call(this);
        this._listWindow.refresh();
    };
    savefileId(): number{
        return this._listWindow.index() + 1;
    };
    createHelpWindow(): void{
        this._helpWindow = new Window_Help(1);
        this._helpWindow.setText(this.helpWindowText());
        this.addWindow(this._helpWindow);
    };
    _helpWindow: Window_Help;
    createListWindow(): void{
        var x = 0;
        var y = this._helpWindow.height;
        var width = Graphics.boxWidth;
        var height = Graphics.boxHeight - y;
        this._listWindow = new Window_SavefileList(x, y, width, height);
        this._listWindow.setHandler('ok',     this.onSavefileOk.bind(this));
        this._listWindow.setHandler('cancel', this.popScene.bind(this));
        this._listWindow.select(this.firstSavefileIndex());
        this._listWindow.setTopRow(this.firstSavefileIndex() - 2);
        this._listWindow.setMode(this.mode());
        this._listWindow.refresh();
        this.addWindow(this._listWindow);
    };
    _listWindow: Window_SavefileList;
    mode(): string{
        return null;
    };
    activateListWindow(): void{
        this._listWindow.activate();
    };
    helpWindowText(): string{
        return '';
    };
    firstSavefileIndex(): number{
        return 0;
    };
    onSavefileOk(): void{
    };
}

//-----------------------------------------------------------------------------
// Scene_Save
//
// The scene class of the save screen.

 class Scene_Save extends Scene_File {
    constructor(){
        super();
        this.initialize.apply(this, arguments);
    }
    initialize(): void{
        Scene_File.prototype.initialize.call(this);
    };
    mode(): string {
        return 'save';
    };
    helpWindowText(): string {
        return TextManager.saveMessage;
    };
    firstSavefileIndex(): number {
        return DataManager.lastAccessedSavefileId() - 1;
    };
    onSavefileOk(): void {
        Scene_File.prototype.onSavefileOk.call(this);
        $gameSystem.onBeforeSave();
        if (DataManager.saveGame(this.savefileId())) {
            this.onSaveSuccess();
        } else {
            this.onSaveFailure();
        }
    };
    onSaveSuccess(): void {
        SoundManager.playSave();
        StorageManager.cleanBackup(this.savefileId());
        this.popScene();
    };
    onSaveFailure(): void {
        SoundManager.playBuzzer();
        this.activateListWindow();
    };
}

//-----------------------------------------------------------------------------
// Scene_Load
//
// The scene class of the load screen.

 class Scene_Load extends Scene_File {
    constructor(){
        super();
        this.initialize.apply(this, arguments);
    }
    initialize(): void{
        Scene_File.prototype.initialize.call(this);
        this._loadSuccess = false;
    };
    _loadSuccess: boolean;

    terminate(): void{
        Scene_File.prototype.terminate.call(this);
        if (this._loadSuccess) {
            $gameSystem.onAfterLoad();
        }
    };
    mode(): string{
        return 'load';
    };
    helpWindowText(): string{
        return TextManager.loadMessage;
    };
    firstSavefileIndex(): number{
        return DataManager.latestSavefileId() - 1;
    };
    onSavefileOk(): void{
        Scene_File.prototype.onSavefileOk.call(this);
        if (DataManager.loadGame(this.savefileId())) {
            this.onLoadSuccess();
        } else {
            this.onLoadFailure();
        }
    };
    onLoadSuccess(): void{
        SoundManager.playLoad();
        this.fadeOutAll();
        this.reloadMapIfUpdated();
        SceneManager.goto(Scene_Map);
        this._loadSuccess = true;
    };
    onLoadFailure(): void{
        SoundManager.playBuzzer();
        this.activateListWindow();
    };
    reloadMapIfUpdated(): void{
        if ($gameSystem.versionId() !== $dataSystem.versionId) {
            $gamePlayer.reserveTransfer($gameMap.mapId(), $gamePlayer.x, $gamePlayer.y);
            $gamePlayer.requestMapReload();
        }
    };
}

//-----------------------------------------------------------------------------
// Scene_GameEnd
//
// The scene class of the game end screen.

 class Scene_GameEnd extends Scene_MenuBase {
    constructor(){
        super();
        this.initialize.apply(this, arguments);
    }
    initialize(): void{
        Scene_MenuBase.prototype.initialize.call(this);
    };
    create(): void{
        Scene_MenuBase.prototype.create.call(this);
        this.createCommandWindow();
    };
    stop(): void{
        Scene_MenuBase.prototype.stop.call(this);
        this._commandWindow.close();
    };
    createBackground(): void{
        Scene_MenuBase.prototype.createBackground.call(this);
        this.setBackgroundOpacity(128);
    };
    createCommandWindow(): void{
        this._commandWindow = new Window_GameEnd();
        this._commandWindow.setHandler('toTitle',  this.commandToTitle.bind(this));
        this._commandWindow.setHandler('cancel',   this.popScene.bind(this));
        this.addWindow(this._commandWindow);
    };
    _commandWindow: Window_GameEnd;

    commandToTitle(): void{
        this.fadeOutAll();
        SceneManager.goto(Scene_Title);
    };
}

//-----------------------------------------------------------------------------
// Scene_Shop
//
// The scene class of the shop screen.

 class Scene_Shop extends Scene_MenuBase {
    constructor(){
        super();
        this.initialize.apply(this, arguments);
    }
    initialize(): void{
        Scene_MenuBase.prototype.initialize.call(this);
    };
    prepare(goods: any[][], purchaseOnly: boolean): void{
        this._goods = goods;
        this._purchaseOnly = purchaseOnly;
        this._item = null;
    };
    _goods: any[][];
    _purchaseOnly: boolean;
    _item: RPGMakerMV.DataAnyItem;
    create(): void{
        Scene_MenuBase.prototype.create.call(this);
        this.createHelpWindow();
        this.createGoldWindow();
        this.createCommandWindow();
        this.createDummyWindow();
        this.createNumberWindow();
        this.createStatusWindow();
        this.createBuyWindow();
        this.createCategoryWindow();
        this.createSellWindow();
    };
    createGoldWindow(): void{
        this._goldWindow = new Window_Gold(0, this._helpWindow.height);
        this._goldWindow.x = Graphics.boxWidth - this._goldWindow.width;
        this.addWindow(this._goldWindow);
    };
    _goldWindow: Window_Gold;
    createCommandWindow(): void{
        this._commandWindow = new Window_ShopCommand(this._goldWindow.x, this._purchaseOnly);
        this._commandWindow.y = this._helpWindow.height;
        this._commandWindow.setHandler('buy',    this.commandBuy.bind(this));
        this._commandWindow.setHandler('sell',   this.commandSell.bind(this));
        this._commandWindow.setHandler('cancel', this.popScene.bind(this));
        this.addWindow(this._commandWindow);
    };
    _commandWindow: Window_ShopCommand;
    createDummyWindow(): void{
        var wy = this._commandWindow.y + this._commandWindow.height;
        var wh = Graphics.boxHeight - wy;
        this._dummyWindow = new Window_Base(0, wy, Graphics.boxWidth, wh);
        this.addWindow(this._dummyWindow);
    };
    _dummyWindow: Window_Base;
    createNumberWindow(): void{
        var wy = this._dummyWindow.y;
        var wh = this._dummyWindow.height;
        this._numberWindow = new Window_ShopNumber(0, wy, wh);
        this._numberWindow.hide();
        this._numberWindow.setHandler('ok',     this.onNumberOk.bind(this));
        this._numberWindow.setHandler('cancel', this.onNumberCancel.bind(this));
        this.addWindow(this._numberWindow);
    };
    _numberWindow: Window_ShopNumber;
    createStatusWindow(): void{
        var wx = this._numberWindow.width;
        var wy = this._dummyWindow.y;
        var ww = Graphics.boxWidth - wx;
        var wh = this._dummyWindow.height;
        this._statusWindow = new Window_ShopStatus(wx, wy, ww, wh);
        this._statusWindow.hide();
        this.addWindow(this._statusWindow);
    };
    _statusWindow: Window_ShopStatus;
    createBuyWindow(): void{
        var wy = this._dummyWindow.y;
        var wh = this._dummyWindow.height;
        this._buyWindow = new Window_ShopBuy(0, wy, wh, this._goods);
        this._buyWindow.setHelpWindow(this._helpWindow);
        this._buyWindow.setStatusWindow(this._statusWindow);
        this._buyWindow.hide();
        this._buyWindow.setHandler('ok',     this.onBuyOk.bind(this));
        this._buyWindow.setHandler('cancel', this.onBuyCancel.bind(this));
        this.addWindow(this._buyWindow);
    };
    _buyWindow: Window_ShopBuy;
    createCategoryWindow(): void{
        this._categoryWindow = new Window_ItemCategory();
        this._categoryWindow.setHelpWindow(this._helpWindow);
        this._categoryWindow.y = this._dummyWindow.y;
        this._categoryWindow.hide();
        this._categoryWindow.deactivate();
        this._categoryWindow.setHandler('ok',     this.onCategoryOk.bind(this));
        this._categoryWindow.setHandler('cancel', this.onCategoryCancel.bind(this));
        this.addWindow(this._categoryWindow);
    };
    _categoryWindow: Window_ItemCategory;
    createSellWindow(): void{
        var wy = this._categoryWindow.y + this._categoryWindow.height;
        var wh = Graphics.boxHeight - wy;
        this._sellWindow = new Window_ShopSell(0, wy, Graphics.boxWidth, wh);
        this._sellWindow.setHelpWindow(this._helpWindow);
        this._sellWindow.hide();
        this._sellWindow.setHandler('ok',     this.onSellOk.bind(this));
        this._sellWindow.setHandler('cancel', this.onSellCancel.bind(this));
        this._categoryWindow.setItemWindow(this._sellWindow);
        this.addWindow(this._sellWindow);
    };
    _sellWindow: Window_ShopSell;

    activateBuyWindow(): void{
        this._buyWindow.setMoney(this.money());
        this._buyWindow.show();
        this._buyWindow.activate();
        this._statusWindow.show();
    };
    activateSellWindow(): void{
        this._categoryWindow.show();
        this._sellWindow.refresh();
        this._sellWindow.show();
        this._sellWindow.activate();
        this._statusWindow.hide();
    };
    commandBuy(): void{
        this._dummyWindow.hide();
        this.activateBuyWindow();
    };
    commandSell(): void{
        this._dummyWindow.hide();
        this._categoryWindow.show();
        this._categoryWindow.activate();
        this._sellWindow.show();
        this._sellWindow.deselect();
        this._sellWindow.refresh();
    };
    onBuyOk(): void{
        this._item = this._buyWindow.item();
        this._buyWindow.hide();
        this._numberWindow.setup(this._item, this.maxBuy(), this.buyingPrice());
        this._numberWindow.setCurrencyUnit(this.currencyUnit());
        this._numberWindow.show();
        this._numberWindow.activate();
    };
    onBuyCancel(): void{
        this._commandWindow.activate();
        this._dummyWindow.show();
        this._buyWindow.hide();
        this._statusWindow.hide();
        this._statusWindow.setItem(null);
        this._helpWindow.clear();
    };
    onCategoryOk(): void{
        this.activateSellWindow();
        this._sellWindow.select(0);
    };
    onCategoryCancel(): void{
        this._commandWindow.activate();
        this._dummyWindow.show();
        this._categoryWindow.hide();
        this._sellWindow.hide();
    };
    onSellOk(): void{
        this._item = this._sellWindow.item();
        this._categoryWindow.hide();
        this._sellWindow.hide();
        this._numberWindow.setup(this._item, this.maxSell(), this.sellingPrice());
        this._numberWindow.setCurrencyUnit(this.currencyUnit());
        this._numberWindow.show();
        this._numberWindow.activate();
        this._statusWindow.setItem(this._item);
        this._statusWindow.show();
    };
    onSellCancel(): void{
        this._sellWindow.deselect();
        this._categoryWindow.activate();
        this._statusWindow.setItem(null);
        this._helpWindow.clear();
    };
    onNumberOk(): void{
        SoundManager.playShop();
        switch (this._commandWindow.currentSymbol()) {
        case 'buy':
            this.doBuy(this._numberWindow.number());
            break;
        case 'sell':
            this.doSell(this._numberWindow.number());
            break;
        }
        this.endNumberInput();
        this._goldWindow.refresh();
        this._statusWindow.refresh();
    };
    onNumberCancel(): void{
        SoundManager.playCancel();
        this.endNumberInput();
    };
    doBuy(number: number): void{
        $gameParty.loseGold(number * this.buyingPrice());
        $gameParty.gainItem(this._item, number);
    };
    doSell(number: number): void{
        $gameParty.gainGold(number * this.sellingPrice());
        $gameParty.loseItem(this._item, number);
    };
    endNumberInput(): void{
        this._numberWindow.hide();
        switch (this._commandWindow.currentSymbol()) {
        case 'buy':
            this.activateBuyWindow();
            break;
        case 'sell':
            this.activateSellWindow();
            break;
        }
    };
    maxBuy(): number{
        var max = $gameParty.maxItems(this._item) - $gameParty.numItems(this._item);
        var price = this.buyingPrice();
        if (price > 0) {
            return Math.min(max, Math.floor(this.money() / price));
        } else {
            return max;
        }
    };
    maxSell(): number{
        return $gameParty.numItems(this._item);
    };
    money(): number{
        return this._goldWindow.value();
    };
    currencyUnit(): string{
        return this._goldWindow.currencyUnit();
    };
    buyingPrice(): number{
        return this._buyWindow.price(this._item);
    };
    sellingPrice(): number{
        return Math.floor(this._item.price / 2);
    };
}

//-----------------------------------------------------------------------------
// Scene_Name
//
// The scene class of the name input screen.

 class Scene_Name extends Scene_MenuBase {
    constructor(){
        super();
        this.initialize.apply(this, arguments);
    }
    initialize(): void{
        Scene_MenuBase.prototype.initialize.call(this);
    };
    prepare(actorId: number, maxLength: number): void{
        this._actorId = actorId;
        this._maxLength = maxLength;
    };
    _actorId: number;
    _maxLength: number;
    create(): void{
        Scene_MenuBase.prototype.create.call(this);
        this._actor = $gameActors.actor(this._actorId);
        this.createEditWindow();
        this.createInputWindow();
    };
    _actor: Game_Actor;
    start(): void{
        Scene_MenuBase.prototype.start.call(this);
        this._editWindow.refresh();
    };
    createEditWindow(): void{
        this._editWindow = new Window_NameEdit(this._actor, this._maxLength);
        this.addWindow(this._editWindow);
    };
    _editWindow: Window_NameEdit|any;
    createInputWindow(): void{
        this._inputWindow = new Window_NameInput(this._editWindow);
        this._inputWindow.setHandler('ok', this.onInputOk.bind(this));
        this.addWindow(this._inputWindow);
    };
    _inputWindow: Window_NameInput;
    onInputOk(): void{
        this._actor.setName(this._editWindow.name());
        this.popScene();
    };
}

//-----------------------------------------------------------------------------
// Scene_Debug
//
// The scene class of the debug screen.

 class Scene_Debug extends Scene_MenuBase {
    constructor(){
        super();
        this.initialize.apply(this, arguments);
    }
    initialize(): void {
        Scene_MenuBase.prototype.initialize.call(this);
    };
    create(): void{
        Scene_MenuBase.prototype.create.call(this);
        this.createRangeWindow();
        this.createEditWindow();
        this.createDebugHelpWindow();
    };
    createRangeWindow(): void{
        this._rangeWindow = new Window_DebugRange(0, 0);
        this._rangeWindow.setHandler('ok',     this.onRangeOk.bind(this));
        this._rangeWindow.setHandler('cancel', this.popScene.bind(this));
        this.addWindow(this._rangeWindow);
    };
    _rangeWindow: Window_DebugRange;
    createEditWindow(): void{
        var wx = this._rangeWindow.width;
        var ww = Graphics.boxWidth - wx;
        this._editWindow = new Window_DebugEdit(wx, 0, ww);
        this._editWindow.setHandler('cancel', this.onEditCancel.bind(this));
        this._rangeWindow.setEditWindow(this._editWindow);
        this.addWindow(this._editWindow);
    };
    _editWindow: Window_DebugEdit;
    createDebugHelpWindow(): void {
        var wx = this._editWindow.x;
        var wy = this._editWindow.height;
        var ww = this._editWindow.width;
        var wh = Graphics.boxHeight - wy;
        this._debugHelpWindow = new Window_Base(wx, wy, ww, wh);
        this.addWindow(this._debugHelpWindow);
    };
    _debugHelpWindow: Window_Base;

    onRangeOk(): void{
        this._editWindow.activate();
        this._editWindow.select(0);
        this.refreshHelpWindow();
    };
    onEditCancel(): void{
        this._rangeWindow.activate();
        this._editWindow.deselect();
        this.refreshHelpWindow();
    };
    refreshHelpWindow(): void{
        this._debugHelpWindow.contents.clear();
        if (this._editWindow.active) {
            this._debugHelpWindow.drawTextEx(this.helpText(), 4, 0);
        }
    };
    helpText(): string{
        if (this._rangeWindow.mode() === 'switch') {
            return 'Enter : ON / OFF';
        } else {
            return ('Left     :  -1\n' +
                    'Right    :  +1\n' +
                    'Pageup   : -10\n' +
                    'Pagedown : +10');
        }
    };
}

//-----------------------------------------------------------------------------
// Scene_Battle
//
// The scene class of the battle screen.

 class Scene_Battle extends Scene_Base {
    constructor() {
        super();
        this.initialize.apply(this, arguments);
    }
    initialize(): void{
        Scene_Base.prototype.initialize.call(this);
    };

    create(): void {
        Scene_Base.prototype.create.call(this);
        this.createDisplayObjects();
    };
    start(): void{
        Scene_Base.prototype.start.call(this);
        this.startFadeIn(this.fadeSpeed(), false);
        BattleManager.playBattleBgm();
        BattleManager.startBattle();
    };
    update(): void{
        var active = this.isActive();
        $gameTimer.update(active);
        $gameScreen.update();
        this.updateStatusWindow();
        this.updateWindowPositions();
        if (active && !this.isBusy()) {
            this.updateBattleProcess();
        }
        Scene_Base.prototype.update.call(this);
    };
    updateBattleProcess(): void{
        if (!this.isAnyInputWindowActive() || BattleManager.isAborting() ||
                BattleManager.isBattleEnd()) {
            BattleManager.update();
            this.changeInputWindow();
        }
    };
    isAnyInputWindowActive(): boolean{
        return (this._partyCommandWindow.active ||
                this._actorCommandWindow.active ||
                this._skillWindow.active ||
                this._itemWindow.active ||
                this._actorWindow.active ||
                this._enemyWindow.active);
    };
    changeInputWindow(): void{
        if (BattleManager.isInputting()) {
            if (BattleManager.actor()) {
                this.startActorCommandSelection();
            } else {
                this.startPartyCommandSelection();
            }
        } else {
            this.endCommandSelection();
        }
    };
    stop(): void {
        Scene_Base.prototype.stop.call(this);
        if (this.needsSlowFadeOut()) {
            this.startFadeOut(this.slowFadeSpeed(), false);
        } else {
            this.startFadeOut(this.fadeSpeed(), false);
        }
        this._statusWindow.close();
        this._partyCommandWindow.close();
        this._actorCommandWindow.close();
    };
    terminate(): void {
        Scene_Base.prototype.terminate.call(this);
        $gameParty.onBattleEnd();
        $gameTroop.onBattleEnd();
        AudioManager.stopMe();
    
        ImageManager.clearRequest();
    };
    needsSlowFadeOut(): boolean {
        return (SceneManager.isNextScene(Scene_Title) ||
                SceneManager.isNextScene(Scene_Gameover));
    };
    updateStatusWindow(): void {
        if ($gameMessage.isBusy()) {
            this._statusWindow.close();
            this._partyCommandWindow.close();
            this._actorCommandWindow.close();
        } else if (this.isActive() && !this._messageWindow.isClosing()) {
            this._statusWindow.open();
        }
    };
    updateWindowPositions(): void {
        var statusX = 0;
        if (BattleManager.isInputting()) {
            statusX = this._partyCommandWindow.width;
        } else {
            statusX = this._partyCommandWindow.width / 2;
        }
        if (this._statusWindow.x < statusX) {
            this._statusWindow.x += 16;
            if (this._statusWindow.x > statusX) {
                this._statusWindow.x = statusX;
            }
        }
        if (this._statusWindow.x > statusX) {
            this._statusWindow.x -= 16;
            if (this._statusWindow.x < statusX) {
                this._statusWindow.x = statusX;
            }
        }
    };
    createDisplayObjects(): void {
        this.createSpriteset();
        this.createWindowLayer();
        this.createAllWindows();
        BattleManager.setLogWindow(this._logWindow);
        BattleManager.setStatusWindow(this._statusWindow);
        BattleManager.setSpriteset(this._spriteset);
        this._logWindow.setSpriteset(this._spriteset);
    };
    createSpriteset(): void {
        this._spriteset = new Spriteset_Battle();
        this.addChild(this._spriteset);
    };
    _spriteset: Spriteset_Battle;
    createAllWindows(): void {
        this.createLogWindow();
        this.createStatusWindow();
        this.createPartyCommandWindow();
        this.createActorCommandWindow();
        this.createHelpWindow();
        this.createSkillWindow();
        this.createItemWindow();
        this.createActorWindow();
        this.createEnemyWindow();
        this.createMessageWindow();
        this.createScrollTextWindow();
    };
    createLogWindow(): void {
        this._logWindow = new Window_BattleLog();
        this.addWindow(this._logWindow);
    };
    _logWindow: Window_BattleLog;
    createStatusWindow(): void {
        this._statusWindow = new Window_BattleStatus();
        this.addWindow(this._statusWindow);
    };
    _statusWindow: Window_BattleStatus;
    createPartyCommandWindow(): void {
        this._partyCommandWindow = new Window_PartyCommand();
        this._partyCommandWindow.setHandler('fight',  this.commandFight.bind(this));
        this._partyCommandWindow.setHandler('escape', this.commandEscape.bind(this));
        this._partyCommandWindow.deselect();
        this.addWindow(this._partyCommandWindow);
    };
    _partyCommandWindow: Window_PartyCommand;
    createActorCommandWindow(): void {
        this._actorCommandWindow = new Window_ActorCommand();
        this._actorCommandWindow.setHandler('attack', this.commandAttack.bind(this));
        this._actorCommandWindow.setHandler('skill',  this.commandSkill.bind(this));
        this._actorCommandWindow.setHandler('guard',  this.commandGuard.bind(this));
        this._actorCommandWindow.setHandler('item',   this.commandItem.bind(this));
        this._actorCommandWindow.setHandler('cancel', this.selectPreviousCommand.bind(this));
        this.addWindow(this._actorCommandWindow);
    };
    _actorCommandWindow: Window_ActorCommand;
    createHelpWindow(): void {
        this._helpWindow = new Window_Help();
        this._helpWindow.visible = false;
        this.addWindow(this._helpWindow);
    };
    _helpWindow: Window_Help;
    createSkillWindow(): void {
        var wy = this._helpWindow.y + this._helpWindow.height;
        var wh = this._statusWindow.y - wy;
        this._skillWindow = new Window_BattleSkill(0, wy, Graphics.boxWidth, wh);
        this._skillWindow.setHelpWindow(this._helpWindow);
        this._skillWindow.setHandler('ok',     this.onSkillOk.bind(this));
        this._skillWindow.setHandler('cancel', this.onSkillCancel.bind(this));
        this.addWindow(this._skillWindow);
    };
    _skillWindow: Window_BattleSkill;
    createItemWindow(): void {
        var wy = this._helpWindow.y + this._helpWindow.height;
        var wh = this._statusWindow.y - wy;
        this._itemWindow = new Window_BattleItem(0, wy, Graphics.boxWidth, wh);
        this._itemWindow.setHelpWindow(this._helpWindow);
        this._itemWindow.setHandler('ok',     this.onItemOk.bind(this));
        this._itemWindow.setHandler('cancel', this.onItemCancel.bind(this));
        this.addWindow(this._itemWindow);
    };
    _itemWindow: Window_BattleItem;
    createActorWindow(): void {
        this._actorWindow = new Window_BattleActor(0, this._statusWindow.y);
        this._actorWindow.setHandler('ok',     this.onActorOk.bind(this));
        this._actorWindow.setHandler('cancel', this.onActorCancel.bind(this));
        this.addWindow(this._actorWindow);
    };
    _actorWindow: Window_BattleActor;
    createEnemyWindow(): void {
        this._enemyWindow = new Window_BattleEnemy(0, this._statusWindow.y);
        this._enemyWindow.x = Graphics.boxWidth - this._enemyWindow.width;
        this._enemyWindow.setHandler('ok',     this.onEnemyOk.bind(this));
        this._enemyWindow.setHandler('cancel', this.onEnemyCancel.bind(this));
        this.addWindow(this._enemyWindow);
    };
    _enemyWindow: Window_BattleEnemy;
    createMessageWindow(): void {
        this._messageWindow = new Window_Message();
        this.addWindow(this._messageWindow);
        this._messageWindow.subWindows().forEach((window: Window_Base) => {
            this.addWindow(window);
        });
    };
    _messageWindow: Window_Message;
    createScrollTextWindow(): void {
        this._scrollTextWindow = new Window_ScrollText();
        this.addWindow(this._scrollTextWindow);
    };
    _scrollTextWindow: Window_ScrollText;
    refreshStatus(): void {
        this._statusWindow.refresh();
    };
    startPartyCommandSelection(): void {
        this.refreshStatus();
        this._statusWindow.deselect();
        this._statusWindow.open();
        this._actorCommandWindow.close();
        this._partyCommandWindow.setup();
    };
    commandFight(): void {
        this.selectNextCommand();
    };
    commandEscape(): void {
        BattleManager.processEscape();
        this.changeInputWindow();
    };
    startActorCommandSelection(): void {
        this._statusWindow.select(BattleManager.actor().index());
        this._partyCommandWindow.close();
        this._actorCommandWindow.setup(BattleManager.actor());
    };
    commandAttack(): void{
        BattleManager.inputtingAction().setAttack();
        this.selectEnemySelection();
    };
    commandSkill(): void{
        this._skillWindow.setActor(BattleManager.actor());
        this._skillWindow.setStypeId(this._actorCommandWindow.currentExt());
        this._skillWindow.refresh();
        this._skillWindow.show();
        this._skillWindow.activate();
    };
    commandGuard(): void{
        BattleManager.inputtingAction().setGuard();
        this.selectNextCommand();
    };
    commandItem(): void {
        this._itemWindow.refresh();
        this._itemWindow.show();
        this._itemWindow.activate();
    };
    selectNextCommand(): void{
        BattleManager.selectNextCommand();
        this.changeInputWindow();
    };
    selectPreviousCommand(): void{
        BattleManager.selectPreviousCommand();
        this.changeInputWindow();
    };
    selectActorSelection(): void{
        this._actorWindow.refresh();
        this._actorWindow.show();
        this._actorWindow.activate();
    };
    onActorOk(): void{
        var action = BattleManager.inputtingAction();
        action.setTarget(this._actorWindow.index());
        this._actorWindow.hide();
        this._skillWindow.hide();
        this._itemWindow.hide();
        this.selectNextCommand();
    };
    onActorCancel(): void{
        this._actorWindow.hide();
        switch (this._actorCommandWindow.currentSymbol()) {
        case 'skill':
            this._skillWindow.show();
            this._skillWindow.activate();
            break;
        case 'item':
            this._itemWindow.show();
            this._itemWindow.activate();
            break;
        }
    };
    selectEnemySelection(): void{
        this._enemyWindow.refresh();
        this._enemyWindow.show();
        this._enemyWindow.select(0);
        this._enemyWindow.activate();
    };
    onEnemyOk(): void{
        var action = BattleManager.inputtingAction();
        action.setTarget(this._enemyWindow.enemyIndex());
        this._enemyWindow.hide();
        this._skillWindow.hide();
        this._itemWindow.hide();
        this.selectNextCommand();
    };
    onEnemyCancel(): void{
        this._enemyWindow.hide();
        switch (this._actorCommandWindow.currentSymbol()) {
        case 'attack':
            this._actorCommandWindow.activate();
            break;
        case 'skill':
            this._skillWindow.show();
            this._skillWindow.activate();
            break;
        case 'item':
            this._itemWindow.show();
            this._itemWindow.activate();
            break;
        }
    };
    onSkillOk(): void{
        var skill = this._skillWindow.item();
        var action = BattleManager.inputtingAction();
        action.setSkill(skill.id);
        BattleManager.actor().setLastBattleSkill(skill);
        this.onSelectAction();
    };
    onSkillCancel(): void{
        this._skillWindow.hide();
        this._actorCommandWindow.activate();
    };
    onItemOk(): void {
        var item = this._itemWindow.item();
        var action = BattleManager.inputtingAction();
        action.setItem(item.id);
        $gameParty.setLastItem(item);
        this.onSelectAction();
    };
    onItemCancel(): void {
        this._itemWindow.hide();
        this._actorCommandWindow.activate();
    };
    onSelectAction(): void{
        var action = BattleManager.inputtingAction();
        this._skillWindow.hide();
        this._itemWindow.hide();
        if (!action.needsSelection()) {
            this.selectNextCommand();
        } else if (action.isForOpponent()) {
            this.selectEnemySelection();
        } else {
            this.selectActorSelection();
        }
    };
    endCommandSelection(): void{
        this._partyCommandWindow.close();
        this._actorCommandWindow.close();
        this._statusWindow.deselect();
    };
    
}

//-----------------------------------------------------------------------------
// Scene_Gameover
//
// The scene class of the game over screen.

 class Scene_Gameover extends Scene_Base {
    constructor(){
        super();
        this.initialize.apply(this, arguments);
    }
    initialize(): void{
        Scene_Base.prototype.initialize.call(this);
    };
    create(): void{
        Scene_Base.prototype.create.call(this);
        this.playGameoverMusic();
        this.createBackground();
    };
    start(): void{
        Scene_Base.prototype.start.call(this);
        this.startFadeIn(this.slowFadeSpeed(), false);
    };
    update(): void{
        if (this.isActive() && !this.isBusy() && this.isTriggered()) {
            this.gotoTitle();
        }
        Scene_Base.prototype.update.call(this);
    };
    stop(): void{
        Scene_Base.prototype.stop.call(this);
        this.fadeOutAll();
    };
    terminate(): void{
        Scene_Base.prototype.terminate.call(this);
        AudioManager.stopAll();
    };
    playGameoverMusic(): void{
        AudioManager.stopBgm();
        AudioManager.stopBgs();
        AudioManager.playMe($dataSystem.gameoverMe);
    };
    createBackground(): void{
        this._backSprite = new Sprite();
        this._backSprite.bitmap = ImageManager.loadSystem('GameOver');
        this.addChild(this._backSprite);
    };
    _backSprite: Sprite;
    isTriggered(): boolean{
        return Input.isTriggered('ok') || TouchInput.isTriggered();
    };
    gotoTitle(): void{
        SceneManager.goto(Scene_Title);
    };
}
